local borenyi = fk.CreateSkill {
    name = "borenyi",
    tags = { Skill.Compulsory },  -- 设为锁定技
}

Fk:loadTranslationTable{
    ["borenyi"] = "仁义",
    [":borenyi"] = "每轮开始时，你可以令X（X为场上人数）个角色摸一张牌，直到本轮结束，其使用的普通锦囊牌对你无效。",
    ["#borenyi"] = "仁义：选择X（X为场上人数）个角色，令其摸一张牌",
    ["$borenyi1"] = "仁言利博，以微惠众。",
    ["$borenyi2"] = "上德若谷，下布万民。",
    ["@@borenyi-round"] = "仁义",
}

-- 修改为每轮开始时触发
borenyi:addEffect(fk.RoundStart, {
    can_trigger = function(self, event, target, player, data)
        -- 确保是技能拥有者，且本轮未使用过技能
        return player:hasSkill(borenyi.name) and 
               player:usedSkillTimes(borenyi.name, Player.HistoryTurn) == 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local all_players = room:getAllPlayers()
        
        -- 选择X个角色（X为场上人数）
        local result = room:askToChoosePlayers(player, {
            targets = all_players,
            min_num = 1,
            max_num = #all_players,
            prompt = "#borenyi",
            skill_name = borenyi.name,
        })
        
        if #result > 0 then
            room:sortByAction(result)
            event:setCostData(self, {tos = result})
            return true
        end
        return false
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local targets = event:getCostData(self).tos
        
        for _, p in ipairs(targets) do
            if not p.dead then
                p:drawCards(1, borenyi.name)
                room:addTableMark(p, "@@borenyi-round", player.id)  -- 标记角色为本轮受影响
            end
        end
    end,
})

-- 拦截普通锦囊牌的使用（保持不变）
borenyi:addEffect(fk.PreCardEffect, {
    anim_type = "defensive",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        -- 检查使用普通锦囊牌的玩家是否被标记，且目标是技能发动者
        local from = data.from
        return data.to == player and 
               data.card:isCommonTrick() and 
               from and 
               table.contains(from:getTableMark("@@borenyi-round"), player.id)
    end,
    on_use = function(self, event, target, player, data)
        data.nullified = true  -- 无效化锦囊牌
    end,
})

return borenyi